#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // Unix Standard 头文件
#include <fcntl.h>
#include <errno.h>
#include <string.h>

int main(int argc, char *argv[])
{

    char buf[1024];

    int n = 0;

    int fd1 = open(argv[1], O_RDONLY); // read

    if (fd1 == -1) {
        perror("open argv[1] error");
        exit(1);
    }

    int fd2 = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0664); // write

    if (fd1 == -1) {
        perror("open argv[2] error");
        exit(1);
    }

    while ((n = read(fd1, buf, 1024)) != 0) {

        if (n < 0) {
            perror("read argv[1] error");
            break;
        }

        write(fd2, buf, n);
    }

    close(fd1);
    close(fd2);

    return 0;
}